function a(x) { 
    split("",x,"") 
}
function binarySearch(goal,a,  mid,lo,hi) {
    lo=1;hi=length(a)
    while(hi > lo) {
	mid  = int((lo + hi)/2)
	here = a[mid]["x"]
	if (here > goal)
	    hi = mid - 1
	else if (here < goal)
	    lo = mid + 1
	else break}
    return mid
}
function klass1(gp,   col) {
    for(col in gp)  
	if (gp[col])
	    return col
}
function nump(x) {
    return x ~ /^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eE][+-]?[0-9]+)?$/
}
function xsort(r1,x1,r2,x2) {
    return x1["x"] - x2["x"]
}
function x2sort(r1,x1,r2,x2) {
    return x1[r1]["x"] - x2[r2]["x"]
}
function abs(x) { return x < 0 ? -1*x : x }
function anybut(l,but1,but2,lives,   x,n) {
    n = int(rand()* length(l)) + 1
    x = l[n]
    if (x==but1 || x==but2) 
	return lives > 9 ? x : anybut(l,but1,but2,lives+1)
    else 
	return x
}
function say(x) {
    printf(x)>"/dev/stdout"
    fflush("/dev/stdout")
}
function o(a,s,  i){
    for(i in a) print s"[" i "]=" a[i]
}
function l2sd(a,    i,n,x,delta,mean,m2) {
    for(i in a) {
	n    += 1
	x     = a[i]
	delta = x - mean
	mean += delta/n
	m2   += delta*(x -mean)
    }
    return sqrt(m2/(n-1))
}
function stars(n,s,   out) {
    s = s ? s : "*"
    while (n-- > 0) out = out s
    return out
}
function pairs(str,lst,   i,tmp,n) {
    split("",lst,"")
    n=split(str,tmp,",")
    for(i=1;i<n;i+=2)
	lst[tmp[i]]=tmp[i+1]
}
function s2l(str,l,   i,tmp,n) {
    split("",l,"")
    n=split(str,tmp,",")
    for(i=1;i<=n;i++)
	l[i]=tmp[i]
}
function l2s(l,sep,form,   one,sep1,s,n,i) {
    form = form ? form : "%5.3f"
    s=""
    n=length(l)
    for(i=1;i<=n;i++)  {
        one = l[i]
        if (nump(one)) 
	    one = sprintf(form,one)
	s = s sep1 one
        sep1 = sep
    }
    return s 
}
